/**
   缓冲区  -> 通道 Channel -> 缓冲区
  
  性能
  1.内存映射最快
  2.NIO读写文件
  3.使用了缓存的IO流
  4.无缓冲的IO流
 Channel就和线程有关系了。

 */
/*
package com.leo.第八章_文件与IO;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileChannel.MapMode;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
public class U8_L20_NewIo_Channel {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		copyFile_Filechannel();
		randomAccessFileCopy();
	}
	public static void randomAccessFileCopy() {
		try {
			//设定 读取和写入的路径
			RandomAccessFile in=new RandomAccessFile("E:\\eclipse-workspace\\test\\oo.jpg","r");
			RandomAccessFile out=new RandomAccessFile("E:\\eclipse-workspace\\test\\nio_filechannal\\oo.jpg","rw");
			
			//设定 读取和写入的管道
			FileChannel fcIn=in.getChannel();
			FileChannel fcOut=out.getChannel();
			//计算文件管道流里文件的大小
			long size=fcIn.size();
			//设定 映射缓冲区   映射到字节缓冲       
			MappedByteBuffer inBuf =fcIn.map(MapMode.READ_ONLY,0,size);
			MappedByteBuffer outBuf =fcOut.map(MapMode.READ_WRITE, 0, size);
			
			for(int i=0;i<size;i++) {
				outBuf.put(inBuf.get());
			}
			fcIn.close();
			fcOut.close();
			in.close();
			out.close();
			System.out.println("映射完毕。over！"+outBuf.toString());
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	public static void copyFile_Filechannel() {
	
		try {
			// 设置 文件读取管道 和文件写入管道 
			FileChannel fcIn=new FileInputStream("E:\\eclipse-workspace\\test\\oo.jpg").getChannel();
			FileChannel fcOut=new FileOutputStream("E:\\eclipse-workspace\\test\\nio_filechannal\\oo.jpg").getChannel();
			//这只读取的缓冲格式 1024个字节
			ByteBuffer buf =ByteBuffer.allocate(1024);
			while(fcIn.read(buf)!=-1) {
				buf.flip();
				fcOut.write(buf);
				buf.clear();
			}
			fcIn.close();
			fcOut.close();
			System.out.println("操作完成");
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
*/